package router

import (
	jwt "gitee.com/sansaniot/ssiot-core/httpmvc/jwtauth"
	"github.com/gin-gonic/gin"

	"ssalarm/internal/alarm/apis"
)

func init() {
	RouterCheckRole = append(RouterCheckRole, registerWsRouter)
}

func registerWsRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
	api := apis.WsApi{}
	// websocket
	wss := v1.Group("/api/alarm/websocket")
	{
		wss.GET("", setAuthMiddleware(authMiddleware), api.ConnectAndListen)
	}
	// http
	r := v1.Group("/api/alarm/ws-client").Use(authMiddleware.MiddlewareFuncWithOutValidate())
	{
		r.GET("/find", api.FindClients)
	}
}

func setAuthMiddleware(authMiddleware *jwt.GinJWTMiddleware) gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Set("authMiddleware", authMiddleware)
	}
}
